<?php
/**
 * XIE--Scorpion
 *
 * 前台展示
 *
 * time 2016-5-13
 */
namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use DB,Input,Redirect,Session,url;
use App\Http\Requests;
use App\Http\Controllers\Controller;
header('content-type:text/html;charset=utf-8');
class JianliController extends Controller
{
  // 基本信息
	public function jianli()
	{    
       $user_id=Session::get('user_id');
       $user_name=Session::get('user_name');
       if(empty($user_name))
       { 
          echo "<script>alert('您还尚未登录，先去登录吧!');</script>".Redirect::action('Home\LoginController@login');
          die();
       }
       $add_time=time();
        if(Input::has('_token'))
          {
             $arr=Input::all(); 
             unset($arr['_token']);
             $filename=time().rand(10,99).'.jpg';
             Input::file('headPic')->move('homes/uploads/images',$filename);
             $arr['headPic']=$filename;
             $roles=DB::table('info')->insert($arr);
             if($roles)
             {
               echo "<script>alert('基本信息已保存成功');</script>".Redirect::action('Home\JianliController@jianli');
             }
             
          }
          else
          {
             $row=DB::select('select * from info order by x_id desc limit 1');
             return view('homes/jianli',compact('row','roles','user_name','add_time','headPic'));
          }
	}

  //期望工作
  public function work()
  {
     $user_id=Session::get('user_id');
   
      if(Input::has('_token'))
      {
         $arr=Input::all();
         unset($arr['_token']);
         // var_dump($arr);die();
         $arr['user_id']=$user_id;
         $roles=DB::table('work')->insert($arr);
         if($roles)
         {
           echo "<script>alert('期望工作已保存成功');</script>".Redirect::action('Home\JianliController@jianli');
         }
      }
      else
      {
          return view('jianli');
      }
  }
	
  // 工作经历
  public function work_experience()
  {
    if(Input::has('_token'))
      {
         $arr=Input::all();
         unset($arr['_token']);
         // var_dump($arr);die();
         $roles=DB::table('work_experience')->insert($arr);
         if($roles)
         {
           echo "<script>alert('工作经历已保存成功');</script>".Redirect::action('Home\JianliController@jianli');
         }
      }
      else
      {
          return view('jianli');
      }
  }

// 项目经验
  public function project_experience()
  {
    if(Input::has('_token'))
      {
         $arr=Input::all();
         unset($arr['_token']);
         var_dump($arr);die();
         $roles=DB::table('project_experience')->insert($arr);
         if($roles)
         {
           echo "<script>alert('项目经验已保存成功');</script>".Redirect::action('Home\JianliController@jianli');
         }
      }
      else
      {
          return view('jianli');
      }
 }

 // 教育背景
 public function school()
 {
    if(Input::has('_token'))
    {
       $arr=Input::all();
       unset($arr['_token']);
       // var_dump($arr);die();
       $roles=DB::table('school')->insert($arr);
       if($roles)
       {
         echo "<script>alert('教育背景已保存成功');</script>".Redirect::action('Home\JianliController@jianli');
       }
    }
    else
    {
        return view('jianli');
    }

 }

 // 自我描述
 public function self()
 {
  if(Input::has('_token'))
    {
       $arr=Input::all();
       unset($arr['_token']);
       // var_dump($arr);die();
       $roles=DB::table('self')->insert($arr);
       if($roles)
       {
         echo "<script>alert('自我描述已保存成功');</script>".Redirect::action('Home\JianliController@jianli');
       }
    }
    else
    {
        return view('jianli');
    }

 }

 public function homework()
 {
   if(Input::has('_token'))
    {
       $arr=Input::all();
       unset($arr['_token']);
       // var_dump($arr);die();
       $roles=DB::table('homework')->insert($arr);
       if($roles)
       {
         echo "<script>alert('作品展示已保存成功');</script>".Redirect::action('Home\JianliController@jianli');
       }
    }
    else
    {
        return view('jianli');
    }

 }

 // 上传简历
 public function upload()
 {
     $s=Input::file('newResume');
     var_dump($s);die();
     $filename=time().rand(10,99).'.txt';
     Input::file('newResume')->move('homes/img',$filename);
     $arr['newResume']=$filename;
     var_dump($arr);die();
     $roles=DB::table('newResume')->insert($arr);
     if($roles)
     {
       echo "<script>alert('简历附件已保存成功');</script>".Redirect::action('Home\JianliController@jianli');
     }
     else
      {
        return view('jianli');
      }

 }

// // 修改
//  public function update()
//  {
     
//      $do=$request->input('do');
//      $stu=$Request->input('stu');
//     if($do=='save')
//      {
//         DB::table('info')->where('id',$id)->update(array($val));
//      }else
//      {
//         DB::table('info')->insert($arr);
//      }


//  }




 public function add()
 {   

      $user_id=Session::get('user_id');
      if(Input::has('_token'))
      {
            $arr=Input::all();
            unset($arr['_token']); 
            $stu=$arr['stu'];
            unset($arr['stu']);
            unset($arr['do']);
            $arr['user_id']=$user_id; 
            // var_dump($arr);die();
            $roles=DB::table($stu)->insert($arr);
            if($roles)
            {
               echo "<script>alert('SUCCESS')</script>";
            }
      }
  }

 
   
}